<?php

use yii\db\Migration;

class m170912_081652_create_mechanicsettlement extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }
    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->createTable('{{%mechanic_settlement}}',[
                'id' => $this->primaryKey()->notNull().' COMMENT \'自增id\'',
                'mechanic_id' => $this->smallInteger()->defaultValue(0).' COMMENT \'机构id\'',
                'status' => $this->smallInteger(1)->defaultValue(0).' COMMENT \'0 未付款 1 已付款\'',
                'commission_money' => $this->decimal(10,2)->defaultValue(0.00).' COMMENT \'补贴/分成\'',
                'payment_method' => $this->string(20)->defaultValue(null).' COMMENT \'付款方式\'',
                'payment_id' => $this->smallInteger(4)->defaultValue(0).' COMMENT \'付款方式id\'',
                'operator' => $this->string(50)->defaultValue(null).' COMMENT \'操作人\'',
                'operator_id' => $this->integer()->defaultValue(0).' COMMENT \'操作人id\'',
                'payment_time' => $this->integer()->defaultValue(0).' COMMENT \'付款时间\'',
                'type' => $this->smallInteger()->defaultValue(1).' COMMENT \'1 补贴 2 分成\'',
                'paymant_operator' => $this->string(50)->defaultValue(null).' COMMENT \'付款人\'',
                'paymant_operator_id' => $this->string(50)->defaultValue(null).' COMMENT \'付款人id\'',
                'created_at' => $this->integer()->defaultValue(0).' COMMENT \'创建时间\''
            ]);
        }
    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach($dbs as $v){
            $this->db = $v;
            $this->dropTable('{{%mechanic_settlement}}');
        }
    }
}
